#!/usr/bin/ruby -Ku
# -*- coding: utf-8 -*-
require 'test/unit'
require 'm3g'

class Test_Object3D < Test::Unit::TestCase
  def setup
  end

  def teadown
  end

  def test_defualt_variables
    obj = M3G::Group.new
    
    assert_equal       0    , obj.animation_track_count
    assert_equal       0    , obj.user_id
    assert_equal       nil  , obj.user_object
    assert_instance_of Array, obj.references
    assert_equal       0    , obj.references.length
  end

  def test_set_variables
    obj = M3G::Group.new
    ary = [1,2,3,4]

    obj.user_id         =  100
    obj.user_object     =  ary

    assert_equal 100       , obj.user_id
    assert_equal ary       , obj.user_object
  end

  def test_animation_track
    obj        = M3G::Group.new
    key_seq    = M3G::KeyframeSequence.new 4, 3, M3G::KeyframeSequence::LINEAR
    anim_track = M3G::AnimationTrack.new key_seq, M3G::AnimationTrack::TRANSLATION
    obj.animation_track << anim_track
    
    assert_equal 1         , obj.animation_track_count
    assert_equal anim_track, obj.animation_track[0]
    
    obj.remove_animation_track anim_track

    assert_equal 0         , obj.animation_track_count
  end

  def test_references
    obj        = M3G::Group.new
    key_seq    = M3G::KeyframeSequence.new 4, 3, M3G::KeyframeSequence::LINEAR
    anim_track = M3G::AnimationTrack.new key_seq, M3G::AnimationTrack::TRANSLATION
    obj.animation_track << anim_track
    
    assert_equal 1         , obj.references.length
    assert_equal anim_track, obj.references[0]
  end

  def find
    obj = M3G::Group.new
    obj.user_id = 100

    assert_equal obj, obj.find(100)
    assert_equal nil, obj.find(101)
  end

  def duplicate
    key_seq    = M3G::KeyframeSequence.new 4, 3, M3G::KeyframeSequence::LINEAR
    anim_track = M3G::AnimationTrack.new key_seq, M3G::AnimationTrack::TRANSLATION
    arry       = [1,2,3,4]

    obj1 = M3G::Group.new
    obj1.user_id = 100
    obj1.user_object = arry
    obj1.animation_track << anim_track

    obj2 = obj1.duplicate

    assert_equal obj1.user_id              , obj2.user_id
    assert_equal obj1.user_object          , obj2.user_object
    assert_equal obj1.animation_track_count, obj2.animation_track_count
    assert_equal obj1.animation_track[0]   , obj2.animation_track[0]
  end
end
